package com.yonyou.sto.modules.ums.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.sto.common.api.CommonResult;
import com.yonyou.sto.modules.ims.model.ImsParty;
import com.yonyou.sto.modules.ums.model.UmsNcCustomer;
import com.yonyou.sto.modules.ums.mapper.UmsNcCustomerMapper;
import com.yonyou.sto.modules.ums.model.UmsNcCusttax;
import com.yonyou.sto.modules.ums.service.UmsNcCustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aegon
 * @since 2022-11-25
 */
@Service
public class UmsNcCustomerServiceImpl extends ServiceImpl<UmsNcCustomerMapper, UmsNcCustomer> implements UmsNcCustomerService {

    @Override
    public Page<UmsNcCustomer> list(String keyword, Integer pageSize, Integer pageNum) {
        Page<UmsNcCustomer> page = new Page<>(pageNum, pageSize);
        QueryWrapper<UmsNcCustomer> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<UmsNcCustomer> lambda = wrapper.lambda();
        lambda.eq(UmsNcCustomer::getDr, 0);//NC dr=0为未被删除
        if (StrUtil.isNotEmpty(keyword)) {
            //lambda.like(UmsNcCustomer::getCode, keyword);
            lambda.like(UmsNcCustomer::getName, keyword);
        }
        lambda.orderByDesc(UmsNcCustomer::getCreatetime);
        return page(page, wrapper);
    }

    @Override
    public List<String> getnames() {
        List<UmsNcCustomer> distinct_names = baseMapper.selectList(new QueryWrapper<UmsNcCustomer>().select("DISTINCT name"));
        List<String> names = new ArrayList<>();
        distinct_names.forEach(
            n -> {
                if (StrUtil.isNotBlank(n.getName())){
                    names.add(n.getName());
                }
            }
        );
        names.add("长飞集团");
        names.add("长天集团");
        return names;
    }


}
